package com.xfatm.killer.task;

import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.xfatm.killer.R;
import com.xfatm.killer.entity.AppInfoController;
import com.xfatm.killer.util.Activitys;

/**
 * Created by wenjie on 2018/3/25.
 */

public class DisableAllAppTask extends AsyncTask<Integer,Integer,Integer>{

    private View btnView;

    public DisableAllAppTask(View btnView){
        this.btnView=btnView;
    }

    @Override
    protected Integer doInBackground(Integer... integers) {
        long now=System.currentTimeMillis();
        AppInfoController.getInstance().disableAllInThread();
        now=now-System.currentTimeMillis();
        if(now<1000){
            try {
                Thread.sleep(1000L-now);
                /*publishProgress(1);
                Thread.sleep(2000);*/
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        publishProgress(2);
        return 100;
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
        TextView textView=btnView.findViewById(R.id.disableText);
        ProgressBar progressBar=btnView.findViewById(R.id.disableProgress);
        textView.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        Toast.makeText(Activitys.top(),"已全部禁用",Toast.LENGTH_SHORT).show();
        AppInfoController.getInstance().getSelectAppInfoAdapter().notifyDataSetChanged();
    }
}
